var myVar=setInterval(function(){GoSmart.getSummary()},5000);
var GoSmart = {
		actualTemperatures : 
        {
            bedroom1: "",
            bedroom2: "",
            livingroom: "",
            lobby: "",
            bathroom: ""
        },
        
        wantedTemperatures : 
        {
        	bedroom1: "",
        	bedroom2: "",
        	livingroom: "",
        	lobby: "",
        	bathroom: ""
        },
		
		getSummary : function() {
			GoSmart.getActualTemperatures();
		},
		
		getActualTemperatures : function() {
			var uri =  "/gosmart/temperature?actualTemperatures";
			$.ajax({
				type: 'GET',
				url: uri,
				dataType: 'json',
				
				success: function(response) 
				{ 
					$("#loading").css ("display", "none");
					GoSmart.actualTemperatures = response.temperatures;
					GoSmart.getWantedTemperatures();
				},
				error: function(xhr, reason, exception) 
				{             	
					
				}
			});
			return false; 
		},
		
		getWantedTemperatures : function() {
			var uri =  "/gosmart/temperature?wantedTemperatures";
			$.ajax({
				type: 'GET',
				url: uri,
				dataType: 'json',
				
				success: function(response) 
				{ 
					$("#loading").css ("display", "none");
					GoSmart.wantedTemperatures = response.temperatures;
					GoSmart.renderTemperature();
				},
				error: function(xhr, reason, exception) 
				{             	
					
				}
			});
			return false; 
		},
		
		renderTemperature : function () {
			$("#content").html("");
			var html = "";
			html += "<table>";
			html += "<thead>";
			html += "<tr><th>Room</th><th>Actual Temp</th><th>Wanted Temp</th></tr>";
			html += "</thead>";
			html += "<tbody>";
			html += "<tr><td>Bedroom1</td><td>" + GoSmart.actualTemperatures.bedroom1 + "</td><td>" + GoSmart.wantedTemperatures.bedroom1 + "</td></tr>";
			html += "<tr><td>Bedroom2</td><td>" + GoSmart.actualTemperatures.bedroom2 + "</td><td>" + GoSmart.wantedTemperatures.bedroom2 + "</td></tr>";
			html += "<tr><td>Livinroom</td><td>" + GoSmart.actualTemperatures.livingroom + "</td><td>" + GoSmart.wantedTemperatures.livingroom + "</td></tr>";
			html += "<tr><td>Lobby</td><td>" + GoSmart.actualTemperatures.lobby + "</td><td>" + GoSmart.wantedTemperatures.lobby + "</td></tr>";
			html += "<tr><td>Bathroom</td><td>" + GoSmart.actualTemperatures.bathroom + "</td><td>" + GoSmart.wantedTemperatures.bathroom + "</td></tr>";
			html += "</tbody>"
			html += "</table>";
			$("#content").html(html);
		}
	}

$(document).ready (function () {
    GoSmart.getSummary();
}); 